<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>canvas海报</title>
  <style type="text/css">
    * {
      margin: 0;
      padding: 0;
    }
  </style>
</head>

<body>
  <h3>Canvas</h3>
  <canvas id="canvas"></canvas>
  <h3>PNG</h3>
  <img id="image" />


  <script>
    var canvas = document.getElementById('canvas');
    canvas.width = 375;
    canvas.height = 600;
    var ctx = canvas.getContext('2d');

    var img  = new Image(),
        qrcode = new Image();
    img.src = './images/w.png';
    qrcode.src = './images/666.png';

    img.onload = function () {
      var title = '变形金刚金刚变形金刚金';
      var price = '￥120'
      ctx.fillStyle = "#fff";
      ctx.fillRect(0, 0, 375, 600);
      ctx.fillStyle = "#000";
      ctx.font = "bold 16px Arial"
      ctx.fillText(title, 16, 435);
      ctx.fillStyle = "#FF0000";
      ctx.font = "bold 40px Arial";
      ctx.fillText(price, 16, 495);
      qrcode.onload = function () {
        ctx.drawImage(img, 0, 20, 375, 375);
        ctx.drawImage(qrcode, 259, 425, 100, 100);
        var image = canvas.toDataURL("image/png");
        document.getElementById('image').src = image;
      }
    }
 
  </script>
</body>

</html>